package com.team.easybuy.controller;

import com.alibaba.fastjson.JSON;
import com.sun.org.apache.bcel.internal.generic.LUSHR;
import com.team.easybuy.entity.Car;
import com.team.easybuy.entity.Collect;
import com.team.easybuy.service.ColService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/col")
public class ColController {

    @Resource
    private ColService colService;

    @RequestMapping("/addCol")
    public String addCol(@RequestBody Map<String, Object> params) {
        String str = JSON.toJSONString(params.get("col"));
        Collect collect = JSON.parseObject(str, Collect.class);
        int id = Integer.parseInt(params.get("id").toString());
        return colService.addCollect(collect, id);
    }

    @RequestMapping("/loadCol/{id}")
    public List<Collect> loadCol(@PathVariable Integer id) {
        return colService.loadCollectList(id);
    }

    @RequestMapping("/delInCol")
    public boolean delInCol(@RequestParam("id") Integer id, @RequestParam("index") int index) {
        return colService.delInCol(id, index);
    }

    @RequestMapping("/delAllCol/{id}")
    public boolean delAllCol(@PathVariable Integer id) {
        return colService.delAllCol(id);
    }
}
